package org.karelun.gef.outline;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import org.eclipse.gef.editparts.AbstractTreeEditPart;
import org.karelun.gef.model.Node;
import org.karelun.gef.model.NodeConstants;

public class NodeTreeEditPart extends AbstractTreeEditPart implements PropertyChangeListener {
	
	public NodeTreeEditPart(Object model) {
		super(model);
	}
	
	@Override
	protected void refreshVisuals() {
		Node node=getNode();
		setWidgetText(node.getText());
	}
	
	@Override
	public void propertyChange(PropertyChangeEvent evt) {
		if(NodeConstants.PROP_TEXT.equals(evt.getPropertyName()))
			refreshVisuals();
	}
	
	public void activate() {
		super.activate();
		getNode().addPropertyChangeListener(this);
	}

	public void deactivate() {
		getNode().removePropertyChangeListener(this);
		super.deactivate();
	}
	
	private Node getNode(){
		return (Node)getModel();
	}
}
